package com.cip.master.dao.impl;

import java.util.List;

import com.cip.admin.dao.impl.CipHibernateDAOSupport;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.cip.master.dao.AcademicDAO;
import com.cip.master.model.Academic;
import com.cip.master.model.Examination;

public class AcademicDAOImpl extends CipHibernateDAOSupport implements AcademicDAO {

	public List<Academic> getAllAcademicList() throws Exception {
		System.out.println("in dao===");
		HibernateTemplate hibernateTemplate = getCipHibernateTemplate();	
		System.out.println("update==");
	    List<Academic> academicList = hibernateTemplate.loadAll(Academic.class);
	    System.out.println("the lis t===>"+academicList.size());
		return academicList;
	}

	public Academic getAcademicById(int id) throws Exception {
		HibernateTemplate hibernateTemplate = getHibernateTemplate();
		 return hibernateTemplate.get(Academic.class, id);
	}

	public Academic saveOrUpdateAcademic(Academic academic) throws Exception {
		getHibernateTemplate().saveOrUpdate(academic);
		return academic;
	}

	public Academic editAcademic(Academic academic) throws Exception {
		getHibernateTemplate().update(academic); 
		return academic;
	}
	
	public Academic getAcademicByYear(String year) throws Exception{
		String query="select academic from Academic as academic where academic.academicYear='"+year+"'";
		List<Academic> academicList = getCipHibernateTemplate().find(query);
		if(academicList.size() > 0){
			return academicList.get(0);
		}
		return null;
	}
	

}
